<template>
  <div>
    <div class="banner" v-if="!$store.state.user">
      <div class="ipone">
        <img src="~@/img/mobile.png" alt="">
      </div><br />
      <span><a href="#/login">登陆</a>/<a>注册</a></span>
    </div>
    <div class="banner1" v-else>
      <div class="base-info">
        <div class="left">
          <van-image round fit="cover" class="avtar"
            :src="userIfndo.data.photo">
            <template v-slot:loading>
              <van-loading type="spinner" size="20" />
            </template>
          </van-image>
          <span>{{userIfndo.data.name}}</span>
        </div>
        <div class="right">
          <van-button round size="small" type="default" class="btn-sum">编辑资料
          </van-button>
        </div>
      </div>
      <div class="list">
        <div class="itmes">
          <span>{{userIfndo.data.art_count}}</span><span>头条</span>
        </div>
        <div class="itmes">
          <span>{{userIfndo.data.follow_count}}</span><span>关注</span>
        </div>
        <div class="itmes">
          <span>{{userIfndo.data.fans_count}}</span><span>粉丝</span>
        </div>
        <div class="itmes">
          <span>{{userIfndo.data.like_count}}</span><span>获赞</span>
        </div>
      </div>
    </div>
    <div>
      <van-grid class="daohang" clickable column-num="2">
        <van-grid-item class="item">
          <i slot="icon" class="toutiao toutiao-shoucang"></i>
          <span slot="text">收藏</span>
        </van-grid-item>
        <van-grid-item class="item">
          <i slot="icon" class="toutiao toutiao-lishi"></i>
          <span slot="text">历史</span>
        </van-grid-item>
      </van-grid>
      <van-cell-group>
        <van-cell title="消息通知" is-link />
        <van-cell title="小智同学" is-link />
      </van-cell-group>
    </div>
    <div class="cancellation" @click="cancellation" v-show="$store.state.user">
      退出登录
    </div>
  </div>
</template>

<script>
import { user } from '@/api/user'
export default {
  data () {
    return {
      userIfndo: {}
    }
  },
  methods: {
    cancellation () {
      this.$dialog.confirm({
        title: '退出登录'
      }).then(() => {
        this.$store.commit('setUser', null)
      })
    }
  },
  async created () {
    try {
      const res = await user()
      this.userIfndo = res.data
    } catch (err) {
      if (err.response.status === 401) {
        this.$notify({ type: 'warning', message: '请登录' })
        this.$store.commit('setUser', null)
      }
    }
  }
}
</script>

<style scoped lang="less">
.banner {
  box-sizing: border-box;
  padding-top: 80px;
  height: 361px;
  width: 100%;
  text-align: center;
  background-image: url(~@/img/banner.png);
  background-size: 100%;
  .ipone {
    display: inline-block;
    width: 132px;
    height: 132px;
    line-height: 132px;
    border-radius: 50%;
    background-color: white;
    img {
      width: 100%;
    }
  }
  span {
    font-size: 34px;
    color: white;
  }
}
.banner1 {
  box-sizing: border-box;
  height: 361px;
  width: 100%;
  text-align: center;
  background-image: url(~@/img/banner.png);
  background-size: 100%;
  .base-info {
    height: 231px;
    padding: 76px 32px 23px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .left {
      display: flex;
      justify-content: space-between;
      align-items: center;

      span {
        font-size: 36px;
        margin-left: 20px;
        color: white;
      }
      .avtar {
        height: 132px;
        width: 132px;
      }
    }
    .right {
      .btn-sum {
        height: 40px;
        line-height: 35px;
      }
    }
  }
  .list {
    height: 100px;
    display: flex;
    justify-content: space-around;
    .itmes {
      flex: 1;
      display: flex;
      justify-content: space-between;
      align-items: center;
      flex-wrap: wrap;
      span {
        font-size: 30px;
        flex: 100%;
        color: white;
      }
    }
  }
}
.daohang {
  .item {
    i.toutiao {
      font-size: 38px;
    }
    i.toutiao-shoucang {
      color: #eb5253;
    }
    i.toutiao-lishi {
      color: #ff9d1d;
    }
    span {
      font-size: 30px;
    }
  }
}
.cancellation {
  border: 1px solid black;
  margin: auto;
  margin-top: 55px;
  width: 600px;
  text-align: center;
  height: 35px;
  font-size: 28px;
}
</style>
